package com.liuweiheng.cloudproviderpayment8002.mq.topic;

import com.liuweiheng.cloudproviderpayment8002.mq.MultiConstant;
import com.liuweiheng.cloudproviderpayment8002.util.RabbitMQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;

public class Provider {

    /**
     * 交换机名称
     */
    public static final String EXCHANGE_NAME = "logs-topic";


    public static void main(String[] args) throws IOException {

        // 获取MQ连接
        Connection connection = RabbitMQUtil.getConnection();

        // 创建通道
        Channel channel = connection.createChannel();

        // 声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME, MultiConstant.TOPIC_EXCHANGE_TYPE, true);

        // 发布消息
        channel.basicPublish(EXCHANGE_NAME, "user.save.123", MessageProperties.PERSISTENT_TEXT_PLAIN, "hello direct".getBytes());

        // 释放资源
        RabbitMQUtil.closeConnection(channel, connection);

    }

}
